//设置pjax，延时30秒就刷新页面
$(document).pjax('a:not(.no-pjax)', '.content-wrapper > .content', {timeout: 30000});
// NProgress.configure({ showSpinner: false });
$(document).on('pjax:start', function () {
  NProgress.start();
});
$(document).on('pjax:end', function () {
  NProgress.done();
});


function getRequest() {
  var url = location.search; // 获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    var strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      var decodeParam = decodeURIComponent(strs[i]);
      var param = decodeParam.split("=");
      if (param[0] !== '') {
        theRequest[param[0]] = param[1];
      }

    }

  }
  return theRequest;
}

function replace_url_param(oUrl, paramName, paramValue) {
  var re = eval('/(' + paramName + '=)([^&]*)/gi');
  var nUrl = oUrl.replace(re, paramName + '=' + paramValue);
  return nUrl;
}


$('body').on('click', '.fb-search-btn', function () {
  var obj = {};
  $('.fb-filter > input').each(function () {
    obj[$(this).attr('id')] = $(this).val();
  });
  fb_serach(obj);
})


function fb_serach(obj) {
  var tUrl = '';
  var oUrl = window.location.href;
  var oRequest = getRequest();
  if (typeof obj === 'object') {
    if (oUrl.indexOf('?') > -1) {
      for (var oo in obj) {
        if (oRequest[oo] != undefined) {
          if (obj[oo] === '') {
            delete oRequest[oo];
          }
          else {
            oRequest[oo] = obj[oo];
          }
        } else {
          if (obj[oo] !== '') {
            oRequest[oo] = obj[oo];
          }
        }
      }
    }
    else {
      for (var oo in obj) {
        oRequest[oo] = obj[oo];
      }
    }
  }

  for (var tt in oRequest) {
    tUrl += tt + '=' + oRequest[tt] + '&';
  }

  if (tUrl != '') {
    location.href = oUrl.split('?')[0] + '?' + tUrl;
  }
  else {
    location.href = oUrl.split('?')[0]
  }

}


$(function () {
  $('.sidebar-menu > li').click(function () {
    $(this).siblings().removeClass('active');
    $(this).addClass('active');
  })

});

